//
//  Gear.m
//  INFSWA02
//
//  Created by Justin van Grootveld on 9/15/11.
//  Copyright 2011 Justinform. All rights reserved.
//

#import "Gear.h"
#import "NoGear.h"

@implementation Gear

@synthesize gear = _gear;

- (id)init
{
    self = [super init];
    if (self) 
    {
        _name = @"Gear";
        [self setGear:nil];
        _physicalAttackPower = 0;
        _magicalAttackPower = 0;
        _physicalDefense = 0;
        _magicalDefense = 0;
        _healthPoints = 0;
        _range = 0;
        _movement = 0;
    }
    
    return self;
}

- (id)initWithGear:(Gear *)g
{
    self = [self init];
    if (self) 
    {
        [self setGear:g];
    }
    
    return self;
}

- (Gear *)gear
{
    return _gear;
}

- (NSString *)name
{
    return _name;
}

- (NSInteger)physicalAttackPower
{
    return _physicalAttackPower + ((_gear) ? [_gear physicalAttackPower] : 0);
}

- (NSInteger)magicalAttackPower
{
    return _magicalAttackPower + ((_gear) ? [_gear magicalAttackPower] : 0);
}

- (NSInteger)physicalDefense
{
    return _physicalDefense + ((_gear) ? [_gear physicalDefense] : 0);
}

- (NSInteger)magicalDefense
{
    return _magicalDefense + ((_gear) ? [_gear magicalDefense] : 0);
}

- (NSInteger)healthPoints
{
    return _healthPoints + ((_gear) ? [_gear healthPoints] : 0);
}

- (NSInteger)range
{
    return _range + ((_gear) ? [_gear range] : 0);
}

- (NSInteger)movement
{
    return _movement + ((_gear) ? [_gear movement] : 0);
}

- (NSString *)listOfGear
{
    NSString *listOfGear = _name;
    Gear *g = _gear; 
    
    while(g)
    {
        listOfGear = [listOfGear stringByAppendingFormat:@", %@", [g name]];
        g = [g gear];
    }
    
    return listOfGear;
}

-(NSString *)description
{
    return [NSString stringWithFormat:@"\nGear: %@ \n\tP-atk: %d \n\tM-atk: %d \n\tP-def: %d \n\tM-def: %d \n\tHp: %d \n\tRange: %d \n\tMove: %d", [self listOfGear], [self physicalAttackPower], [self magicalAttackPower], [self physicalDefense], [self magicalDefense], [self healthPoints], [self range], [self movement]];
}

@end
